//
//  LXPermissionHomeKit.swift
//  LXPermissionAuth
//
//  Created by yoctech on 2021/8/18.
//

import UIKit
import HomeKit

@objc class LXPermissionHomeKit: NSObject, LXPermissionProtocol {
    @objc public static func auth(autoRequestIfNot: Bool, clouser: @escaping LXAuthClouser) {
        if #available(iOS 13.0, *) {
            switch HMHomeManager().authorizationStatus {
            case .authorized:
                clouser(true,  .authorized)
            case .determined:
                clouser(false,  .notDetermined)
            case .restricted:
                clouser(false,  .restricted)
            default:
                clouser(false,  .other)
            }
        } else {
            if (HMHomeManager().primaryHome != nil) {
                clouser(true,  .authorized)
            }else{
                clouser(false,  .other)
            }
        }
    }
    

}
